<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet
   version="2.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:fn="http://www.w3.org/2005/xpath-functions"
>

<xsl:output method="xml" 
	indent="yes" 
	name="eadxml" />

<xsl:template match="ead/archdesc/dsc/c">

	<xsl:message>Creating <xsl:value-of select="concat(position(), '.xml')" /></xsl:message>

	<xsl:result-document format="eadxml" href="{concat(position(), '.xml')}" >
		<xsl:element name="ead">
			<xsl:copy-of select="../../../eadheader" />
			<xsl:element name="archdesc">
				<xsl:copy-of select="../../../archdesc/@*" />
				<xsl:copy-of select="../../../archdesc/*[not(name(.)='dsc')]" />
				<xsl:element name="dsc">
					<xsl:copy-of select="../../dsc/@*" />
					<xsl:copy-of select="." />
				</xsl:element>
			</xsl:element>
		</xsl:element>
	</xsl:result-document>

</xsl:template>

</xsl:stylesheet>

